<?php
class Server {
  public static function submit_atdn($orm, $sys, $inst, $is_iframe) {
    $req = json_decode(Utils::get_param('req', '[]'));
    
    if ($req->log == 1) {
      $obj = new stdClass();
      $obj->class_id = $req->class_id;
      $obj->start = $req->start;
      $obj->add_at = date('Y-m-d', time());
      $orm->add('pb_colg_atdnlog', $obj);
      $obj->id = $orm->last_id();
    }
    
    foreach ($req->atdn as $itm) {
      if (isset($itm->id) && $itm->id != 0) {
        $orm->update('pb_colg_atdn', $itm);
      } else {
        $itm->atdnlog_id = $obj->id;
        $orm->add('pb_colg_atdn', $itm);
        $itm->id = $orm->last_id();
      }
    }
    
    echo json_encode($req->atdn);
  }
}
?>